package cn.hallele.bbts.crawler.service.actions.unionlotto.pipeline;

import cn.hallele.bbts.crawler.common.constants.CCConstant;
import cn.hallele.bbts.crawler.common.constants.KafkaConstant;
import cn.hallele.bbts.crawler.service.bo.LotteryDataBO;
import cn.hutool.extra.spring.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.List;

/**
 * UnionLottoPipeline
 *
 * @author anle5
 * @since 2023/12/3 星期日 13:01
 */
@Slf4j
public class UnionLottoPipeline implements Pipeline {
    private final KafkaTemplate<String, List<LotteryDataBO>> TEMPLATE = SpringUtil.getBean("kafkaTemplate");

    /**
     * Process extracted results.
     *
     * @param resultItems resultItems
     * @param task        task
     */
    @Override
    public void process(ResultItems resultItems, Task task) {
        List<LotteryDataBO> lotteryDataBOS = resultItems.get(CCConstant.PIPELINE_RESULT);
        log.info("Get a responseJson: {}", lotteryDataBOS.size());
        TEMPLATE.send(KafkaConstant.TOPIC_CRAWLER_UNION_LOTTO, lotteryDataBOS);
    }
}
